﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Sekretar.Repository;
using System.Linq;

namespace Sekretar
{
    public partial class RazlogPrimanjaRecView : Common.Forms.RecView
    {
        RRazlogPrimanja rp = new RRazlogPrimanja();
        int id;

        public RazlogPrimanjaRecView(int id)
        {
            InitializeComponent();
            this.id = id;
        }

        private void RazlogPrimanjaRecView_Load(object sender, EventArgs e)
        {
            if (id == 0)
                RPBindingSource.DataSource = rp.Nov();
            else
                RPBindingSource.DataSource = rp.Izmeni(this.id);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                RPBindingSource.EndEdit();
                int i = rp.Snimi((DataLayer.RazlogPrimanja)RPBindingSource.Current);
                this.Index = rp.VratiSve().ToList().FindIndex(c => c.RazlogPrimanjaId == i);
            }
            catch (Exception ex)
            {
                Common.Tools.MessageError.Show(ex.Message);
                this.DialogResult = DialogResult.None;
            }
        }
    }
}
